package com.sfteam.bmw.api;

import java.util.Map;

import com.jfinal.core.Controller;
import com.jfinal.kit.StrKit;
import com.jfinal.log.Log;
import com.sfteam.bmw.model.Feedback;
import com.sfteam.bmw.vo.AjaxResult;

/**
 * 用户反馈api
 * 
 * @author knight322
 *
 */
public class FeedbackApi extends Controller {

	static Log logger = Log.getLog(FeedbackApi.class);

	private AjaxResult result = new AjaxResult();

	/**
	 * 新增反馈
	 */
	public void create() {
		// 意见反馈
		String content = getPara("content");
		// 联系方式
		String email = getPara("email");
		// 图片
		String img = getPara("img");

		Feedback fb = new Feedback();
		fb.set("content", content);
		if (StrKit.notBlank(email)) {
			fb.set("email", email);
		}
		fb.set("img", img);
		Map<String, String> map = getSessionAttr(getPara("token"));
		fb.set("openId", map.get("openid"));
		if (fb.save()) {
			result.success("保存成功！");
		} else {
			result.addError("保存失败");
		}
		renderJson(result);
	}
}
